import cv2
import numpy as np
img1=cv2.imread("images/b.jpg")
img2=cv2.imread("images/a.jpg")
img1=cv2.resize(img1,(640,640),interpolation=cv2.INTER_AREA)


#新建画布
maskDIY= np.zeros((640,640),np.uint8)
#画圆
cv2.circle(maskDIY,(330,300),80,255,-1, cv2.LINE_AA)
#画矩形
pts = np.array([[50,50],[250,50],[250,250],[50,250]],np.int32)
pts = pts.reshape((-1,2,1))
cv2.fillPoly(maskDIY,[pts],255,cv2.LINE_AA)

cv2.imshow("img1",img1)
cv2.imshow("img2",img2)
cv2.imshow("mask",maskDIY)
#按掩膜复制

cv2.copyTo(img2,mask=maskDIY,dst=img1)
#img1=img2.copy(mask=maskDIY)
cv2.imshow("result",img1)
cv2.waitKey(0)





